package com.ruitu.health_2.ui.activity;

import android.os.Bundle;
import android.view.View;

import com.ruitu.health_2.R;
import com.ruitu.health_2.mvp.model.ModelModel;
import com.ruitu.health_2.mvp.presenter.ModelPresenter;
import com.ruitu.health_2.ui.common.BaseModel2Activity;
import com.ruitu.router_module.bean.home.AdvertContent;
import com.ruitu.router_module.bean.home.MallHomeData;
import com.ruitu.router_module.bean.product.ArtMan;

import java.util.List;

public class EduCulture2Activity extends BaseModel2Activity<ModelPresenter.EduCulture2P, ModelModel.EduCultureM> {

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_edu_culture2;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        reqData();
        hideProgress();
        showProgress();

        setHeadTitle("教育文化");
    }

    // 请求首页的一些数据
    protected void reqData() {
        rxList.add(p.reqEduCultureHomeData());
    }

    @Override
    public void onReqComplete(int code, boolean isOk, Object data) {
        if (code == 1) {
            refresh.refreshComplete(true, 800);
            scroll_view.post(new TopHeightRunnable());// 计算顶部高度
            mallHomeData = (MallHomeData) data;
            tabColumnList = mallHomeData.getTabColumnList();
            columnList = mallHomeData.getColumnList();

            // 设置横向的艺人数据
            artManList.clear();
            List<AdvertContent<ArtMan>> adArtManList = mallHomeData.getArtManList();
            for (int i = 0; i < adArtManList.size(); i++) {
                AdvertContent<ArtMan> adArtMan = adArtManList.get(i);
                artManList.add(adArtMan.getInfoObject());// 封装新的艺人对象
                artManList.get(i).setAvaterUrl(adArtMan.getImgUrl());// 修改艺人图片url为外层的广告图片地址
            }
            artManAdapter.setDataList(artManList);

            setDataToView();

            currPosId = tabColumnList.get(tab.getSelectedTabPosition()).getPosId();

            vp_pro.setAdapter(vpAdapter);
            tab.setupWithViewPager(vp_pro);
            tab_2.setupWithViewPager(vp_pro);
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == tv_more_art_man) {// 更多艺人
            Bundle bundle = new Bundle();
            bundle.putInt("type", 1);
            startActivity(ArtManListActivity.class);
        }
    }
}
